<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class customers_invoice {
  function loaddata() {
    global $masterclass;

    $masterclass->loadmodule('customers');
    $masterclass->loadmodule('personnel');

    $masterclass->loadjavascript('invoices');
    $masterclass->loadjavascript('customers');

    $masterclass->websiteconfig['javascript_include'][]='include/date-picker-alt.js';
    
    $masterclass->loadjavascript('',$masterclass->mainconfig['v4rootdir'].'include/suckertreemenu.inc.js');
    
    if (isset($masterclass->sitevars['customerid']) && $masterclass->sitevars['customerid']!='') {
      $masterclass->websiteconfig['title']=$masterclass->allclasses['customers']->fetch_customername($masterclass->sitevars['customerid']);
    } else {
      $masterclass->websiteconfig['title']='New Customer';
    }
    
    $masterclass->site['postfields'][] = array(
      'table'=>'customers',
      'trackingid'=>'customerid',
      'fields'=>array(

        'first'=>'customers_customerfirst',
        'last'=>'customers_customerlast',
        'spouse'=>'customers_customerspouse',
        'company'=>'customers_customercompany',
        'emaila'=>'customers_customeremaila',
        'emailb'=>'customers_customeremailb',
        'dayphone'=>'customers_customerdayphone',
        'dayphoneext'=>'customers_customerdayphoneext',
        'nightphone'=>'customers_customernightphone',
        'nightphoneext'=>'customers_customernightphoneext',
        'otherphonea'=>'customers_customerotherphonea',
        'otherphoneaext'=>'customers_customerotherphoneaext',
        'otherphoneb'=>'customers_customerotherphoneb',
        'otherphonebext'=>'customers_customerotherphonebext',
        'fax'=>'customers_customerfax',
        'address'=>'customers_customeraddress',
        'apt'=>'customers_customerapt',
        'city'=>'customers_customercity',
        'state'=>'customers_customerstate',
        'zip'=>'customers_customerzip',

        'personnel'=>'customers_salesperson'
      ),
      'static'=>array(
        'active'=>'1'
      )
    );
    
  return;
  }

  function savedata() {
    global $masterclass;
    

    foreach ($masterclass->sitevars['post_action'] as $postaction) {
      switch ($postaction) {
       case 'customers_save':
       
        if ($masterclass->sitevars['customerid']<1 || $masterclass->sitevars['customerid']=='') {
          $masterclass->site['postfields'][] = array(
            'table'=>'customerscounter',
            'fields'=>array(
              'customer'=>'customerid'
            ),
            'static'=>array(
              'camefrom'=>'Manual Input',
              'inputtrackingvar'=>$masterclass->site['trackingvar'],
              'inputtrackingid'=>$masterclass->site[$masterclass->site['trackingvar']]
            )
          );

          $masterclass->sitevars['customers_customerfirst']=ucwords($masterclass->sitevars['customers_customerfirst']);
          $masterclass->sitevars['customers_customerlast']=ucwords($masterclass->sitevars['customers_customerlast']);
          $masterclass->sitevars['customers_customerspouse']=ucwords($masterclass->sitevars['customers_customerspouse']);
          $masterclass->sitevars['customers_customercompany']=ucwords($masterclass->sitevars['customers_customercompany']);
          $masterclass->sitevars['customers_customeraddress']=ucwords($masterclass->sitevars['customers_customeraddress']);
          $masterclass->sitevars['customers_customercity']=ucwords($masterclass->sitevars['customers_customercity']);
          $masterclass->sitevars['customers_customerstate']=strtoupper($masterclass->sitevars['customers_customerstate']);
          
          $newcustomerflag='1';
        }
        $masterclass->savedata();
       
       
        if (isset($masterclass->sitevars['customers_customernotes']) && $masterclass->sitevars['customers_customernotes']!='') {
          $masterclass->allclasses['customers']->add_customernotes($masterclass->sitevars['customers_customernotes'],date("Y-m-d H:i"),$masterclass->allclasses['personnel']->fetch_personnelname($masterclass->site['personnelid']));
        }
        
        if ($newcustomerflag=='1') {
          $masterclass->site['forward']=$masterclass->mainconfig['dir'].'invoices/customers_invoice.php?'.$masterclass->trackingvar_query();
        } else {
          $masterclass->site['forward']='window.close();';
        }
       break;
       case 'customers_deletecustomer':
       
        $dbinfo = array(
          'table'=>'customers',
          'trackingid'=>'customerid',
          'static'=>array('active'=>'0')
        );
        $masterclass->uploaddata($dbinfo);
        
        /*
        $strsql = sprintf("UPDATE `invoices_documents` SET `active`='0' WHERE `customer`=%d",$masterclass->allclasses['mysql_functions']->formatmysqldbl($masterclass->sitevars['customerid']));
        $masterclass->allclasses['mysql_functions']->run_query($strsql);
         */
         
         $masterclass->site['forward']='window.close();';
        break;
      }
    }
    
  return;
  }

  function invoices_removeinvoice() {
    global $masterclass;

    if (isset($_POST['rsargs'])) {
      $masterclass->sitevars['invoicesid']=$_POST['rsargs'][1];
    }
    $dbinfo = array(
      'table'=>'invoices_documents',
      'trackingid'=>'invoicesid',
      'static'=>array('active'=>'0')
    );
    $masterclass->uploaddata($dbinfo);
  return;
  }
  function invoices_savepayment() {
    global $masterclass;

    $invoiceid=$_POST['rsargs'][1];
    $paymentdate=$_POST['rsargs'][2];

    $masterclass->sitevars['invoicesid']=$invoiceid;

    $dbinfo = array(
      'table'=>'invoices_documents',
      'trackingid'=>'invoicesid',
      'static'=>array('paid'=>$paymentdate)
    );
    $masterclass->uploaddata($dbinfo);

  return;
  }

  function display_customerinvoices($containername='',$listview='',$pg='') {
    global $masterclass;
    $arrret=array();
    
    if (isset($_POST['rsargs']) && !empty($_POST['rsargs'])) {
      $containername=$_POST['rsargs'][1];
      $listview=$_POST['rsargs'][2];
      $pg=$_POST['rsargs'][3];
    }

    $masterclass->loadmodule('invoices');

    if ($masterclass->sitevars['customerid']>0) {

      if ($pg<0) { $pg=1; }

      $strwhere='';
      if ($documenttype!='') {
        if ($strwhere!='') { $strwhere.=' AND '; }
        $strwhere.=sprintf(" (`documenttype`='%s') ",$masterclass->format_str($documenttype));
      }
      if ($strwhere!='') { $strwhere.=' AND '; }
      $strwhere.=sprintf(" (`active`='1') AND (`customer`=%d AND `customer`>0) ",$masterclass->format_dbl($masterclass->sitevars['customerid']));

      $listcnt=$masterclass->fetch_recordcount('invoices_documents',$strwhere);
      $listpgcount=ceil($listcnt/$masterclass->websiteconfig['entriesperpage']);
      $listarray=$masterclass->fetch_records('`invoices_documents`',$pg,$strwhere,' `paid`, `updated` DESC ',$masterclass->websiteconfig['entriesperpage']);

      $arrret['load_listpage']=$pg;
      $arrret['load_listpagecnt']=$listpgcount;
      $arrret['load_listcnt']=$listcnt;
      $masterclass->site['grabdata_vars']['load_listpage']=$pg;
      $masterclass->site['grabdata_vars']['load_listpagecnt']=$listpgcount;
      $masterclass->site['grabdata_vars']['load_listcnt']=$listcnt;      
    } else {
      $listarray=array();
      $arrret['load_listpage']=1;
      $arrret['load_listpagecnt']=1;
      $arrret['load_listcnt']=0;      
      $masterclass->site['grabdata_vars']['load_listpage']=1;
      $masterclass->site['grabdata_vars']['load_listpagecnt']=1;
      $masterclass->site['grabdata_vars']['load_listcnt']=0;
    }

    //$ret=$masterclass->allclasses['invoices']->display_customerinvoiceslist($listarray);\
    $ret='';
    $ret.='<table width="100%" align="center" cellpadding="0" cellspacing="0" class="sitebox_content">';
    if (empty($listarray->fields)) {
      $ret.='<tr valign="top">';
      $ret.='<td width="100%" valign="middle" style="padding-left:2px;text-align:center;">No Invoices</td>';
      $ret.='</tr>';
    } else {
      while (!$listarray->EOF) {
          
        $csstype=$listarray->fields['documenttype'];
        if ($listarray->fields['paid']=='0000-00-00' || $listarray->fields['paid']=='') { $csstype='unpaid'; }
        
        $arrinvoicetotals=array();
        $itemslist=$masterclass->allclasses['invoices']->fetch_invoices_items($listarray->fields['id']);
        if (!empty($itemslist)) { $arrinvoicetotals=$masterclass->allclasses['invoices']->calc_invoicetotal($itemslist); }
        
        $removeinvoiceclick='OnClick="if (confirm(\'Remove Invoice\\nInvoice #'.$listarray->fields['documentid'].'?\')) { invoices_remove_invoice(\'invoices_removeinvoice\',\''.$listarray->fields['id'].'\'); }" ';

        $trclass=' class="sitebox_invoiceslist_'.$csstype.'" ';
        $tdclass=' class="sitebox_invoiceslist_'.$csstype.'" ';
        
        $onmouseover=' OnMouseOver="this.className=\'sitebox_content_mouseover\';" OnMouseOut="this.className=\'sitebox_invoiceslist_'.$csstype.'\';" ';
        
        $ret.='<tr valign="top" '.$trclass.' style="cursor:pointer;" '.$onmouseover.' >';
        
        $openclick=' OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/showinvoice.php?invoicesid='.$listarray->fields['id'].'\',\'invoices_show'.$listarray->fields['id'].'\',\'760\',\'600\');" ';
        $emailinvoiceclick=' OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/showinvoice_emailpdf.php?invoicesid='.$listarray->fields['id'].'\',\'invoices_emailpdf'.$listarray->fields['id'].'\',\'540\',\'360\');" ';
        $pdfclick=' OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/showinvoice_pdf.php?nohtml=1&invoicesid='.$listarray->fields['id'].'\',\'invoices_pdf'.$listarray->fields['id'].'\',\'540\',\'360\');" ';

        $ret.='<td '.$openclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/book_go.png" border="0" alt="Open" title=" Open "></td>';
        $ret.='<td '.$pdfclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/page_white_acrobat.png" border="0"  alt="Open PDF" title=" Open PDF "></td>';
        $ret.='<td '.$emailinvoiceclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/email_go.png" border="0" alt="E-Mail" title=" E-Mail "></td>';
        //$ret.='<td '.$paymentinvoiceclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/money_dollar.png" border="0" alt="'.$paymenttitle.'" title=" '.$paymenttitle.' "></td>';
        $ret.='<td '.$removeinvoiceclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/cross.png" border="0" alt="Delete" title=" Delete "></td>';

        $ret.='<td '.$openclick.' '.$tdclass.' width="25" valign="middle" style="padding-left:2px;text-align:left;border-bottom:1px solid;"><nobr>#'.$listarray->fields['documentid'].'</nobr>&nbsp;</td>';
        $ret.='<td '.$openclick.' '.$tdclass.' width="5" valign="middle" style="padding-left:2px;text-align:left;border-bottom:1px solid;"><nobr>';
          if ($listarray->fields['paid']!='0000-00-00') { 
            $ret.='PAID';
          } else {
            if ($listarray->fields['documenttype']=='invoice') {
              $ret.='OPEN';
            } else {
              $ret.=strtoupper($listarray->fields['documenttype']);
            }
          }
        $ret.='</nobr>&nbsp;</td>';
        if ($listarray->fields['paid']!='0000-00-00') {
          $ret.='<td '.$openclick.' '.$tdclass.' valign="middle" style="padding-left:2px;text-align:right;border-bottom:1px solid;"><nobr>'.$listarray->fields['paid'].'</nobr>&nbsp;</td>';
        } else {
          $ret.='<td '.$openclick.' '.$tdclass.' valign="middle" style="padding-left:2px;text-align:right;border-bottom:1px solid;"><nobr>'.$listarray->fields['documentdate'].'</nobr>&nbsp;</td>';
        }
        $ret.='<td '.$openclick.' '.$tdclass.' valign="middle" style="padding-left:2px;padding-right:2px;text-align:right;border-bottom:1px solid;"><nobr>$'.number_format($arrinvoicetotals['total'],2).'</nobr>&nbsp;</td>';
        $ret.='</tr>';
        
      $listarray->MoveNext();
      }
    }
    $ret.='</table>';

    $arrret['load_list']=$ret;
    $arrret['load_containername']=$containername;
    
    $masterclass->site['grabdata_vars']['load_list']=$arrret['load_list'];
    $masterclass->site['grabdata_vars']['load_containername']=$arrret['load_containername'];

  return $arrret;
  }
  

  function display_customerpayments($containername='',$listview='',$pg='') {
    global $masterclass;
    $arrret=array();
    
    if (isset($_POST['rsargs']) && !empty($_POST['rsargs'])) {
      $containername=$_POST['rsargs'][1];
      $listview=$_POST['rsargs'][2];
      $pg=$_POST['rsargs'][3];
    }

    $masterclass->loadmodule('invoices');

    if ($masterclass->sitevars['customerid']>0) {

      if ($pg<0) { $pg=1; }

      $strwhere='';
      if ($strwhere!='') { $strwhere.=' AND '; }
      $strwhere.=sprintf(" (`customer`=%d) ",$masterclass->format_dbl($masterclass->sitevars['customerid']));

      $listcnt=$masterclass->fetch_recordcount('invoices_payments',$strwhere);
      $listpgcount=ceil($listcnt/$masterclass->websiteconfig['entriesperpage']);
      $listarray=$masterclass->fetch_records('`invoices_payments`',$pg,$strwhere,' `updated` DESC ',$masterclass->websiteconfig['entriesperpage']);
           
    }

    //$ret=$masterclass->allclasses['invoices']->display_customerinvoiceslist($listarray);\
    $ret='';
    $ret.='<table width="100%" align="center" cellpadding="0" cellspacing="0" class="sitebox_content">';
    if (empty($listarray->fields)) {
      $ret.='<tr valign="top">';
      $ret.='<td width="100%" valign="middle" style="padding-left:2px;text-align:center;">No Payments</td>';
      $ret.='</tr>';
    } else {
      while (!$listarray->EOF) {
 
        $onmouseover=' OnMouseOver="this.className=\'sitebox_content_mouseover\';" OnMouseOut="this.className=\'sitebox_content\';" ';
        //$openclick=' OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/showpayment.php?paymentid='.$listarray->fields['id'].'\',\'payment_show'.$listarray->fields['id'].'\',\'760\',\'600\');" ';

        $trclass=' class="sitebox_content" ';
        $tdclass=' class="sitebox_content" ';

        $ret.='<tr valign="top" '.$trclass.' style="cursor:pointer;" '.$onmouseover.' >';
        

        $ret.='<td '.$refundpaymentclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/arrow_rotate_clockwise.png" border="0" alt="Refund" title=" Refund "></td>';
        $ret.='<td '.$voidpaymentclick.' width="20" valign="middle" style="padding-left:3px;text-align:left;border-bottom:1px solid;border-right:1px solid;cursor:pointer;"><img src="'.$masterclass->mainconfig['dir'].'art/money_delete.png" border="0" alt="Void" title=" Void "></td>';

        $ret.='<td '.$openclick.' '.$tdclass.' width="50" valign="middle" style="padding-left:2px;padding-right:2px;text-align:left;border-bottom:1px solid;"><nobr>$'.money_format('%i',$listarray->fields['paymentamt']).'</nobr>&nbsp;</td>';
        $ret.='<td '.$openclick.' '.$tdclass.' valign="middle" style="padding-left:2px;text-align:left;border-bottom:1px solid;"><nobr>'.$listarray->fields['paymenttype'].'</nobr>&nbsp;</td>';
        $ret.='<td '.$openclick.' '.$tdclass.' width="50" valign="middle" style="padding-left:2px;text-align:right;border-bottom:1px solid;"><nobr>'.$listarray->fields['paymentdate'].'</nobr>&nbsp;</td>';
        $ret.='</tr>';
        
      $listarray->MoveNext();
      }
    }
    $ret.='</table>';
     
    $arrret['load_list']=$ret;
    $arrret['load_containername']=$containername;
    $arrret['load_listpage']=1;
    $arrret['load_listpagecnt']=1;
    $arrret['load_listcnt']=0;   
        
    $masterclass->site['grabdata_vars']['load_list']=$arrret['load_list'];
    $masterclass->site['grabdata_vars']['load_containername']=$arrret['load_containername'];
    $masterclass->site['grabdata_vars']['load_listpage']=$arrret['load_listpage'];
    $masterclass->site['grabdata_vars']['load_listpagecnt']=$arrret['load_listpagecnt'];
    $masterclass->site['grabdata_vars']['load_listcnt']=$arrret['load_listcnt'];

  return $arrret;
  }
  
  function customers_savenote() {
    global $masterclass;

    $addedby=$_POST['rsargs'][1];
    $dispdate=$_POST['rsargs'][2];
    $customernote=$_POST['rsargs'][3];

    $masterclass->allclasses['customers']->add_customernotes($customernote,$dispdate,$addedby);
    $customernotes=$masterclass->allclasses['customers']->fetch_customernotes($masterclass->sitevars['customerid']);
    if ($customernotes!='') { $ret=$customernotes; } else { $ret=''; }

    $masterclass->site['grabdata_vars']['customer_notes']=$ret;
  }
  function display() {
  global $masterclass;

  $customers_customerupdated=$masterclass->allclasses['customers']->fetch_customerupdated($masterclass->sitevars['customerid']);
?>
<script language="javascript">
  function display_calendar(containername,caltime,calview) {
    opener.display_calendar(containername,caltime,calview);
  }
</script>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top">
    <td>
<?php
  if (isset($masterclass->sitevars['customerid']) && $masterclass->sitevars['customerid']!='') {
    $pageheader='<table width="100%" cellpadding="0" cellspacing="0" border="0" class="sitebox_pageheader"><tr>';
    $pageheader.='<td style="text-align:left;">'.$masterclass->sitevars['customers_customerfirst'].' '.$masterclass->sitevars['customers_customerlast'].' ['.$masterclass->sitevars['customerid'].']</td>';
    $pageheader.='<td style="text-align:right;" width="25"><nobr>'.$masterclass->displayhtmlvalue(date("m-d-Y",strtotime($customers_customerupdated['updated']))).'</nobr></td>';
    $pageheader.='</tr></table>';
    echo $masterclass->allclasses['websites']->sitebox_pageheader($pageheader,'');
  } else {
    $pageheader='<table width="100%" cellpadding="0" cellspacing="0" border="0" class="sitebox_pageheader"><tr>';
    $pageheader.='<td style="text-align:left;">New Customer</td>';
    $pageheader.='<td style="text-align:right;" width="25"><nobr>'.$masterclass->displayhtmlvalue(date("m-d-Y")).'</nobr></td>';
    $pageheader.='</tr></table>';
    echo $masterclass->allclasses['websites']->sitebox_pageheader($pageheader,'');
  }

?>
  </td>
  </tr>
</table>
<?php
$nav='';
$nav.='<div class="sitebox_navigation" style="width:100%;">';
$nav.='<ul id="sitebox_navmenu">';
$nav.='<li OnClick="jsshowloadingscreen();add_post_action(\'customers_save\');document.getElementById(\'frm\').submit();"><a>Save</a></li>';
if (isset($masterclass->sitevars['customerid']) && $masterclass->sitevars['customerid']>0) {
  $nav.='<li OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/quote.php?'.$masterclass->trackingvar_query().'\',\'_blank\',\'760\',\'480\');"><a>New Invoice</a></li>';
  $nav.='<li OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/makepayment.php?'.$masterclass->trackingvar_query().'\',\'_blank\',\'760\',\'480\');"><a>New Payment</a></li>';
  $nav.='<li OnClick="if (confirm(\'DELETE\n\nAre You Sure?\')) { jsshowloadingscreen();add_post_action(\'customers_deletecustomer\');document.getElementById(\'frm\').submit(); }"><a>Delete</a></li>';
}
$nav.='<li OnClick="window.close();"><a>Close</a></li>';
$nav.='</ul>';
$nav.='<br style="clear: left;" />';
$nav.='</div>';
echo $nav;
?>
<table width="100%" cellpadding="2" cellspacing="5" border="0">
  <tr valign="top">
  <td width="40%">
<?php
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Customers Information','');
?>
<table width="100%" align="center" cellpadding="0" cellspacing="1" class="sitebox_content">
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>First Name:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerfirst','37%','11');?>&nbsp;&nbsp;Spouse&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerspouse','37%','11');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>Last Name:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerlast');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Company:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customercompany');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">E-Mail:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customeremaila','65%');?>&nbsp;<input type="button" value="email" OnClick=""></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">E-Mail:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customeremailb','65%');?>&nbsp;<input type="button" value="email" OnClick=""></nobr></td>
  </tr>
  <tr valign="bottom">
    <td  valign="middle" style="padding-left:2px;text-align:right;"><nobr>Day Phone:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerdayphone','75%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerdayphoneext','20%','6');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>Night Phone:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customernightphone','75%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customernightphoneext','20%','6');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>1st Cell:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerotherphonea','75%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerotherphoneaext','20%','6');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td  valign="middle" style="padding-left:2px;text-align:right;"><nobr>2nd Cell:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerotherphoneb','75%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerotherphonebext','20%','6');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Fax:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerfax');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Address:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customeraddress');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Apt/Bldg #:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerapt');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">City:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customercity');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">State:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerstate','15%','3','5');?>&nbsp;&nbsp;&nbsp;Zip:&nbsp;&nbsp;</span><?php echo $masterclass->allclasses['websites']->disp_inputtext('customers_customerzip','40%','12');?></nobr></td>
  </tr>
</table>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
?>
</td><td width="60%">
<?php
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Invoices','');
  
  $unquieid='customerinvoiceslist_container';
  $updatelist_click='update_'.$unquieid.'();';

  $runcmdpre='';
  $cngpg_cmd="cngpg('display_customerinvoices','$unquieid',".$unquieid."_listview,document.getElementById('pagelist$unquieid').selectedIndex+1,'');";
  $runcmdpost=$cngpg_cmd;
  
  $listdata=$this->display_customerinvoices($unquieid,'invoice',1);
  echo $masterclass->allclasses['websites']->disp_pages($runcmdpre,$runcmdpost,$unquieid,$listdata['load_listpage'],$listdata['load_listpagecnt']);
?>
<div id="<?php echo $unquieid; ?>"><?php echo $listdata['load_list']; ?></div>
<script language="javascript">
  var <?php echo $unquieid; ?>_listview='invoice';
  function update_<?php echo $unquieid;?>() {
    <?php echo $cngpg_cmd; ?>
  }
</script>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
echo $masterclass->allclasses['websites']->sitebox_vspacer('15');
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Payments','');
  
  $unquieid='customerpaymentlist_container';
  $updatelist_click='update_'.$unquieid.'();';

  $runcmdpre='';
  $cngpg_cmd="cngpg('display_customerpayments','$unquieid',".$unquieid."_listview,document.getElementById('pagelist$unquieid').selectedIndex+1,'');";
  $runcmdpost=$cngpg_cmd;
  
  $listdata=$this->display_customerpayments($unquieid,'',1);
  echo $masterclass->allclasses['websites']->disp_pages($runcmdpre,$runcmdpost,$unquieid,$listdata['load_listpage'],$listdata['load_listpagecnt']);
?>
<div id="<?php echo $unquieid; ?>"><?php echo $listdata['load_list']; ?></div>
<script language="javascript">
  var <?php echo $unquieid; ?>_listview='';
  function update_<?php echo $unquieid;?>() {
    <?php echo $cngpg_cmd; ?>
  }
</script>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
?>
</td></tr><tr valign="top"><td colspan="2">
<?php
/* Start Customer Notes Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Notes','');
?>
<div id="customernotes_savingcontainer" style="height:105px;display:none;"><?php echo $masterclass->websiteconfig['page_procesing']; ?></div>
<div id="customernotes_container">
<?php
  $nav='';
  if ($masterclass->sitevars['customerid']!='') {
    $nav.='<input type="button" class="button" OnClick="customers_sendnote(\'customers_savenote\',\''.$masterclass->allclasses['personnel']->fetch_personnelname($masterclass->site['personnelid']).'\');" value=" Save Note ">&nbsp;&nbsp;';
  }
  $nav.='<input type="button" class="button" OnClick="document.getElementById(\'customers_customernotes\').value=\'\';" value=" Clear ">&nbsp;&nbsp;';
  echo $masterclass->allclasses['websites']->sitebox_navigation($nav);
?>
<table width="100%" align="center" cellpadding="0" cellspacing="0" class="sitebox_content">
    <td width="95%"><div style="text-align:center;border:0;padding:0;"><?php echo $masterclass->allclasses['websites']->disp_textarea('customers_customernotes','100%','3','60');?></div></td>
  </tr>
</table>
</div>
<div style="padding:0;border:0;text-align:left;border-top:1px solid;" id="frame_customers_notes" class="sitebox_content">
<?php $customers_customernotes=$masterclass->allclasses['customers']->fetch_customernotes($masterclass->sitevars['customerid']); echo $masterclass->displayhtmlvalue($customers_customernotes,4); ?>
</div>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Customer Notes Window */
?>
</td></tr></table>
<?php

  return;
  }
}
?>